class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        unordered_map<int,int> hash;
        int sum = 0 , count = 0 , ret = 0;
        hash[0] = 1;
        for(auto& x : nums)
        {
            sum += x;
            ret = (sum % k + k) % k;
            if(hash.count(ret))
            {
                count += hash[ret];
            }
            hash[ret]++;
        }
        return count;
    }
};
